count occurrences of each character